/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vista;

import java.io.IOException;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;
import nexus.adec.GestorEspacioDB;

public class Image{
   public void show(String id){
       
        try {
            byte[] bytes=GestorEspacioDB.getInstance().recuperarImagen(id);
            // Get response.
            FacesContext context = FacesContext.getCurrentInstance();
            HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();

            // Write image contents to response.
            response.setContentType("image/jpeg");
            response.setContentLength(bytes.length);
            response.getOutputStream().write(bytes);
            context.responseComplete();
        } catch (IOException e) {
            System.out.println("Showing image failed, I/O error");
        }
   }
} 